﻿// @@ 2023/09/27 @ 江东新风 @@

namespace 设施信息显示
{

	class Main
	{

		Main()
		{
			//显示设施相关信息，为了减少运算量，放一起
			pk::bind(120, pk::trigger120_t(func_信息显示_设施信息));

		}

		void func_信息显示_设施信息()
		{
			pk::point cursor_pos = pk::get_cursor_hex_pos();
			if (pk::is_valid_pos(cursor_pos))
			{
				pk::building@ building = pk::get_building(cursor_pos);
				if (building is null) return;  //非目标设施不显示
				if (!building.is_player()) return;
				int is_target_facility = check_facitliy(building.facility);
				if (is_target_facility != 0)
				{
					int city_id = pk::get_city_id(cursor_pos);
					pk::city@city = pk::get_city(city_id);
					float population = float(ch::get_base_p(city_id).population);
					float 人口税率基数 = 大城市人口上限 / 75.f;//300w/100=3w
					float rate = 1.0f;
					if (is_target_facility == 1)
					{
						int basic_yield = inter::cal_gold_yield(city, false).first;
						rate = inter::get_market_efficiency(population, basic_yield); 
						//rate = pk::max(0.5f, pk::min(1.1f, ((population / 人口税率基数) / (basic_yield / 30.f))));//2000000/40000 = 50,10个？	
						pk::draw_text(pk::encode(pk::format("市场效率:{:.2f}", rate)), pk::hex_pos_to_screen_pos(cursor_pos, 2, -3.0f), 0xFF00FFFF, FONT_BIG, 0xff000000);					
					}
					else
					{
						int basic_yield = inter::cal_food_yield(city, false).first;
						rate = inter::get_farm_efficiency(population, basic_yield);
						//rate = pk::max(0.5f, pk::min(1.1f, ((population / 人口税率基数) / (basic_yield / 100.f))));//2000000/40000 = 50,10个？
						pk::draw_text(pk::encode(pk::format("农场效率:{:.2f}", rate)), pk::hex_pos_to_screen_pos(cursor_pos, 2, -3.0f), 0xFFFFFF00, FONT_BIG, 0xff000000);
					}
					
				}
				
				

				//float 人口影响倍率 = basic_yield > 0 ? pk::min(1.1f, pk::max(0.4f, ((population / 人口税率基数) / (basic_yield / 30.f)))) : 1.0f;

				//market_yield = int(market_yield * 人口影响倍率);
				//if (调试模式) pk::trace(pk::format("{}人口收入：{}，market_yield:{},基础收入：{}，人口影响倍率：{}", pk::decode(pk::get_name(city)), population_yield, market_yield, basic_yield, 人口影响倍率));

			}
		}

		int check_facitliy(int facility_id)
		{
			//设施_市场1级
			if (facility_id == 设施_市场1级 or facility_id == 设施_市场2级 or facility_id == 设施_市场3级) return 1;
			if (facility_id == 设施_农场1级 or facility_id == 设施_农场2级 or facility_id == 设施_农场3级) return 2;
			//if (facility_id > 设施_铜雀台 and facility_id < 设施_兵舍1级) return true;//为市场1级农场1级的范围
			//if (facility_id > 设施_军屯农 and facility_id < 设施_兵舍2级) return true;//为市场23级农场23级的范围
			return 0;
		}

	}
	Main main;
}
